﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.ExportToRTR.CApExportToRTRRobotSupplementRail
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.ExportToRTR.YAML;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.ExportToRTR{

internal class CApExportToRTRRobotSupplementRail : CApExportToRTRRobotSupplementExternalAxisBase
{
  private HashSet<ITxLocatableObject> m_railAttachments;

  public CApExportToRTRRobotSupplementRail(
    ITxDevice rail,
    ITxLocatableObject attachmentParent,
    TxRobot robot,
    string root,
    HashSet<ITxLocatableObject> railAttachments)
    : base(rail, attachmentParent, robot, root)
  {
    this.m_railAttachments = railAttachments;
  }

  protected override List<ITxObject> GetJointsToExport()
  {
    return ((IEnumerable<ITxObject>) this.m_device.DrivingJoints).ToList<ITxObject>().FindAll((Predicate<ITxObject>) (x => ((Collection<ITxObject>) this.m_robot.ExternalAxes).Contains(x)));
  }

  public override void Export()
  {
    using (TxPoseData currentPose = this.m_device.CurrentPose)
    {
      ((IEnumerable<ITxObject>) this.m_device.DrivingJoints).ToList<ITxObject>().FindAll((Predicate<ITxObject>) (x => ((Collection<ITxObject>) this.m_robot.ExternalAxes).Contains(x))).ForEach((Action<ITxObject>) (x => (x as TxJoint).CurrentValue = 0.0));
      this.ExportJointsWithChildLinks();
      this.ExportSupplememts();
      this.m_device.CurrentPose = currentPose;
    }
  }

  protected void ExportSupplememts()
  {
    TxKinematicLink childLink = (((IEnumerable<ITxObject>) this.m_robot.ExternalAxes).ToList<ITxObject>().Find((Predicate<ITxObject>) (x => (x as TxJoint).Device == this.m_device)) as TxJoint).ChildLink;
    foreach (ITxLocatableObject railAttachment in this.m_railAttachments)
      new CApExportToRTRRobotSupplement(railAttachment, (ITxLocatableObject) childLink, this.m_robot, this.m_root).Export();
    RobotInstance robotInstance = CApExportToRTRYamlMgr.Instance.GetObj((ITxObject) this.m_robot) as RobotInstance;
    TxTransformation origin = CApExportToRTRRobotSupplement.GetOrigin((ITxLocatableObject) this.m_robot, (ITxLocatableObject) childLink, (ITxObjectCollection) this.m_robot);
    Mate mate = robotInstance.Mate;
    mate.Name = CApExportToRTRYamlUtils.GetMateUniqueName((ITxObject) childLink, (ITxObject) this.m_robot);
    mate.Parent = CApExportToRTRRobotSupplement.CreateParentObj((ITxLocatableObject) childLink, (ITxObjectCollection) this.m_robot);
    mate.Child = robotInstance.CreateObjectRef();
    mate.OffsetXyz = new Vec3D(origin.Translation);
    mate.OffsetRpy = new Vec3D(origin.GetRotation());
  }
}
